<--- %%NOBANNER%% --> portrait.sas
 BackForward

/*-------------------<-- Start of Description-->---------------------\
| Change the current word page to portrait;                          |
| Note: 1. that if you change the page from landscape to portrait,   |
|       the landscape will be continued until the end of the         |
|       document;                                                    |
|       2. Word use portrait as default, so you don't have to        |
|       use this function to change the layout of the word document  |
|       to portrait;                                                 |
|---------------------<-- End of Description-->----------------------|
|--------------------------------------------------------------------|
|------------<-- Start of Files or Arguments Needed-->---------------|
| Arguments:                                                         |
|    wordref - not necessary; default is "wordsys";                  |
|-------------<-- End of Files or Arguments Needed-->----------------|
|--------------------------------------------------------------------|
|------------------<-- Start of Files Created-->---------------------|
| Example: %landscape;                                               |
|          %portrait;                                                |
| Usage:   %portait(wordref);                                        |
\-------------------<-- End of Files Created-->---------------------*/
%macro portrait/parmbuff;
/*--------------------------------------------\
| Author:  Duo Zhou;                          |
| Created: 2-27-2001 11:39pm;                 |
| Purpose: Change the format of the pages in  |
|          the word document to portrait;     |
\--------------------------------------------*/
%local arg fref wsid rc;
%let arg=%qscan(&syspbuff,1,%str((),));
%let fref=; %let wsid=0;
%if (%index(%quote(%upcase(%sysfunc(compress(%quote(&arg))))),%str(WORDREF=))) or 
    (%index(%quote(%upcase(%sysfunc(compress(%quote(&arg))))),%str(WINREF=))) or 
    (%index(%quote(%upcase(%sysfunc(compress(%quote(&arg))))),%str(WINDOW=))) or
    (%index(%quote(%upcase(%sysfunc(compress(%quote(&arg))))),%str(WIN=)))
      %then %do;
   %let fref=%qscan(&arg, 2, %str(= ));
   %put --> Note: Checking the status of window "&fref" to see if it is opened.;
%end;
%else %if (%quote(&arg) ne) %then %do;
   %if not (%index(%quote(%upcase(%sysfunc(compress(%quote(&arg))))),%str(=))) %then %do; 
      %let fref=%sysfunc(compress(&arg));
      %put --> Note: Checking the status of window "&fref" to see if it is open.;
   %end;
   %else %do;
      %put --> Alert! Keyword Parameter isn%str(%')t declared!;
   %end;
%end;
%else %if (%quote(&arg) eq) %then %do;
   %let fref=wordsys;
   %put --> Note: No window reference is specified%str(;) Checking the status of the default; 
   %put -->"&fref" to see if it is open.;
%end;
%if (%quote(&fref) ne) %then %do;
   %let wsid=%sysfunc(fopen(&fref,o,132,e));
%end;
%if &wsid %then %do;
   %let rc=%sysfunc(fclose(&wsid));
   data _null_;
      file &fref lrecl=2000;
      length str $2000.;
      str='[FilePageSetup .Tab = "1",.PaperSize = "0", .TopMargin = "1" + Chr$(34),
                          .BottomMargin = "1" + Chr$(34), .LeftMargin = "1.25" + Chr$(34),
                          .RightMargin = "1.25" + Chr$(34), .Gutter = "0" + Chr$(34)]';
      put str;
      str='[FilePageSetup .PageWidth = "8.5" + Chr$(34), .PageHeight = "11" + Chr$(34),
                          .Orientation = 0, .FirstPage = 0, .OtherPages = 0, .VertAlign = 0,
                          .ApplyPropsTo = 1, .FacingPages = 0, .HeaderDistance = "0.5" + Chr$(34)]';
      put str;
      str='[FilePageSetup .FooterDistance = "0.5" + Chr$(34), .SectionStart = 2,
                          .OddAndEvenPages = 0, .DifferentFirstPage = 0, .Endnotes = 0,
                          .LineNum = 0, .StartingNum = "", .FromText = ""]';
      str='[FilePageSetup .CountBy = "0", .NumMode = -1]';
      put str;
   run;
%end;
%else %do;
   %put ==> Alert! Incorrect window reference "&fref", or window "&fref" isn%str(%')t open.;
%end;
%mend portrait;